Skip to content

feat: image models on custom providers (personal and shared) - #611

Open
gganebnyi wants to merge 6 commits into
doop-design:mainfrom
FusionWorks:feature/custom-provider-image-models
Open

gganebnyi wants to merge 6 commits into
doop-design:mainfrom
FusionWorks:feature/custom-provider-image-models

Conversation

@gganebnyi

Copy link
Copy Markdown

Stacked on #609 (shared model providers). Review/merge #609 first; this branch is based on its head; the last three commits
(560c607, b8e4ddc, d39e23e) are this PR.

Why

generate_image only draws with the built-in registry (GPT Image, Nano Banana, Seedream). Teams that self-host an
image model behind an OpenAI Images-compatible endpoint (a LiteLLM gateway in front of ComfyUI/FLUX, vLLM, LocalAI) have
no way in: OPENAI_IMAGES_URL is server-wide, takes registry ids only and runs on an OpenAI key, which since #609 no
longer draws for people who have a shared provider.

What

  • A Chat Completions custom provider (personal or an admin's shared one) can list image models beside its chat
    models: imageModels: { id, name?, transparent? }[], at most 20. Validated in parseCustomProviderConfig; stored in
    the existing custom jsonb, so no migration, and descriptions stored before keep parsing.
  • Settings → Doop Agent → Image model lists them after the registry for whoever has the provider connected and on
    (one row per provider, "Name (shared)" for a shared one). The pick is stored in image_prefs as
    custom:<id>/<model id>. With no pick, the person's own credentials come first (registry accounts, then custom image
    models) and only then anything a server key pays for (Seedream on ARK_API_KEY included), so someone whose only
    connection is a shared provider draws on it from their first sign-in. Disconnecting a personal provider or deleting a
    shared one deletes the picks on it.
  • generate_image draws through POST {baseUrl}/images/generations over customProviderFetch (respecting
    DOOP_CUSTOM_PROVIDERS / DOOP_CUSTOM_PROVIDER_PRIVATE_HOSTS, DNS pinning, no redirects, size cap) with the
    provider's key and headers and the same body as imageApiGenerator. Reads data[0].b64_json; a data[0].url is
    fetched the same way, with credentials only when it is on the base URL's origin. PNG/JPEG/WebP only.
  • Billing: a custom provider is the person's own connection (a shared one: the company's endpoint). A pick that
    cannot run (switched off, deleted, delisted, feature off) refuses with the fix — never a fallback to another
    model or a server key.
  • Errors: 401/403 on a shared provider says "ask your admin (Admin → Shared models)", as feat(admin): shared model providers for everyone on the instance #609's run failures do; on
    a personal one, "update the key in Settings". 404/unknown model names the model and /images/generations. Endpoint
    text (error bodies, 429s, an error.message beside a 200) has the key and header values masked with feat(admin): shared model providers for everyone on the instance #609's
    redactSecrets.
  • generate_image (MCP and resident) gains an optional transparent; only a model marked transparent is sent
    background: "transparent", and the result says whether the image drawn actually has transparency (read off the
    image, alpha kept in the WebP). The agent guide and the README tool table say so.
  • Form: an "Image models" section in CustomProviderForm (Settings and Admin), Chat Completions only; Fetch models
    offers ids for both lists. Admin's shared row shows the image-model count. Strings in en and pt-BR.
  • Analytics get custom-personal / custom-shared (server billed_to and the Settings pick event), never the
    provider's name or model id.

Spec: .context/specs/custom-provider-image-models.md (+ INDEX, TECHSTACK, .env.example).

Tests

  • customProvider.test.ts — parsing: normalising, cap, ids, duplicates, names, Anthropic drops them, stored configs
    without the field; the preference ref.
  • customProviderImages.test.ts — request shape, personal and shared draws, default for a shared-only user while server
    keys are set, picker entries, switched-off / deleted / delisted picks refusing without network, URL responses with and
    without credentials, non-image answers, error wording, private hosts.
  • sharedModelAccounts.test.ts — through the real getAccounts, and gone with DOOP_CUSTOM_PROVIDERS=false.
  • customProviderImagesHttp.test.ts — real server + stub images endpoint: admin adds image models, a non-admin cannot
    change them (404 admin routes, 403 personal route), picker lists and picks them, MCP generate_image stores the image
    drawn on the shared key, 401 wording, switched-off draws nothing, personal provider path, key in no response.
  • customProviderForm.test.tsx, imageModelCard.test.tsx — the form section and the picker rows.

bun run typecheck ✓ · bun run lint ✓ · bun run test: all green except tests/serverListen.test.ts (IPv6 on the
dev machine, fails on the base branch too).

Manually: dev server + a stub images endpoint — admin added a shared provider with an image model through the Admin
form (Fetch models → image list, Transparent on), a new user saw it checked in Settings → Image model, and MCP
generate_image with transparent: true stored a 1024×1024 WebP billed to the provider; the stub received the shared
key and background: "transparent"; no response carried the key.

Notes for review

  • quality and output_format are GPT Image fields; a strict server that refuses unknown fields will 400. LiteLLM and
    most gateways pass or drop them. Happy to add a per-model "plain request" switch if wanted.
  • A provider still needs at least one chat model; image models are offered only while it is on. Image-only providers
    would need the agent default and composer to skip providers without chat models — left out on purpose.
  • Image models are Chat Completions only (the Anthropic Messages API has no images endpoint).

🤖 Generated with Claude Code

https://claude.ai/code/session_01ABWHJg7QHZpRjDADALswQZ

@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[High impact] Shared providers and custom image models affect agent and image workflows across an instance.

Fix the lost connection retries before merging; also mask endpoint errors before shortening them.

Findings

  1. P1 Dropped connections no longer retry ▶
  2. P2 Security Errors can expose shortened secrets ▶

Summary

Adds image models to personal and shared custom providers.

  • Admins can share model providers while users keep their own settings.
  • Custom providers can list image models that users can pick in Settings.
  • generate_image can draw through a selected custom image model.

Acknowledged limits: gganebnyi noted that strict endpoints may reject GPT Image fields and deferred broader request support. gganebnyi also explicitly left image-only providers out of scope; providers still require a chat model.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Settings image pick] --> B[Resolve payer accounts]
  B --> C{Saved custom pick available?}
  C -->|No| D[Refuse without fallback]
  C -->|Yes| E[POST images/generations]
  E --> F{Image response}
  F -->|Base64| H[Check image format]
  F -->|URL| G[Guarded fetch; credentials only on same origin]
  G --> H
  H --> I[Encode WebP and store asset]
Loading

Reviews (1) · Last reviewed commit: "docs: image models on custom providers s..." · Reviewed by Greptile

Comment thread server/agentModel.ts Outdated
Comment on lines +282 to +283
const Class = ERROR_CLASSES.find((candidate) => error instanceof candidate) ?? Error
return new Class(message)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Dropped connections no longer retry

redactedError drops the error's code and cause, which isInterruptedModelTurn uses to recognize a dropped connection. When a custom provider's request fails with ECONNRESET or UND_ERR_SOCKET, the wrapper turns it into a plain Error. retryModelTurn then stops the run instead of retrying it. Preserve the retry signal without keeping secret-bearing error details.

Comment thread server/imageGen.ts Outdated
Comment on lines +530 to +533
const detail = typeof body?.error === 'string' ? body.error : body?.error?.message
throw new Error(
detail
? `${config.name} did not generate an image: ${detail.slice(0, 300)}`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 security Errors can expose shortened secrets

drawCustom shortens error.message before redactedImageError masks secrets. If an endpoint quotes the shared key across character 300, the shortened key no longer matches redactSecrets, so its prefix reaches the caller unchanged. HTTP error bodies have the same problem at the 400-character limit in responseError. Mask the full text before shortening it, and cover both boundaries in tests.

How this was verified: Both error paths shorten endpoint text before exact-value masking, and the MCP tool returns the resulting message to the caller.

@kgoedecke

Copy link
Copy Markdown
Collaborator

@gganebnyi this is a sick PR, can you check on the greptile comments and then we can get that in.

@gganebnyi

Copy link
Copy Markdown
Author

Sure, will do tomorrow

gganebnyi and others added 6 commits November 25, 2026 10:52
An instance admin adds a custom provider once (any OpenAI Chat Completions
or Anthropic Messages endpoint) and every signed-in person gets it beside
their own connections. The definition, key and headers live in
shared_model_accounts (key and headers sealed); each person's model,
effort and on/off live in shared_model_account_prefs (migration 0062).

getAccounts/getAccount merge the enabled ones after the person's own
accounts as accounts marked shared, so the composer, the default (someone
with no account of their own runs on the first one on), the free-tier
meter and runs need no change. Picks write the person's prefs row; edit
and disconnect of a shared kind are refused with 403, and the set-up
probes never fall back to a shared key. A person sees the endpoint's
origin only. DOOP_CUSTOM_PROVIDERS=false hides them.

Admin routes under /api/admin/shared-providers list, add, edit (a key
left out is kept), switch on or off, delete (with every person's prefs),
and list models or test before saving, through the same validation and
probes as personal providers, which move from index.ts to
customProviders.ts. No response carries the key or header values, the
admin's included, and the stored ones only go to the origin they were
saved for: a probe or edit for another origin must bring its own.

For billing a shared provider is the person's own connection: it lifts
the free-tier meter, and the server's image keys stop drawing for them as
for anyone with a connection. Run failures on a shared provider tell the
person to ask their admin rather than to reconnect it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ABWHJg7QHZpRjDADALswQZ
Admin → Shared models lists each shared provider (name, API type, host,
model count, whether a key is set) with an on/off switch, Edit and Remove,
and empty, loading, error and switched-off states. Adding and editing open
the custom provider form in admin mode: the same fields, Fetch models and
Test, through the admin routes; the key is never shown and blank keeps it.

In Settings → Doop Agent a shared provider is a connection row with a
"Shared by your admin" badge: its model, switch and Make default work;
Edit provider and Disconnect are not offered. The composer names a shared
runner "Name (shared)" so it reads apart from a personal provider of the
same name. Strings in en and pt-BR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ABWHJg7QHZpRjDADALswQZ
A Chat Completions custom provider can list image models next to its chat
models (`imageModels: { id, name?, transparent? }[]`, at most 20, in the
same `custom` jsonb, so no migration; descriptions stored before keep
parsing). Whoever has the provider connected and on, an admin's shared
one included, finds them in GET /api/image-model after the registry and
can pick one (stored in image_prefs as `custom:<id>/<model id>`). With no
pick, the first one is the default once nothing on the registry can run,
so a person whose only connection is a shared provider draws on it from
their first sign-in.

generate_image draws through POST {baseUrl}/images/generations over
customProviderFetch (private hosts, DNS pinning, no redirects, size cap)
with the provider's key and headers and imageApiGenerator's body. It reads
data[0].b64_json, or fetches data[0].url the same way, sending the
credentials only to the base URL's origin, and accepts PNG, JPEG or WebP
only. It is billed as the person's own connection; a pick that cannot run
(switched off, deleted, delisted, or custom providers off) refuses with
the fix and never falls back to another model or a server key. A 401/403
on a shared provider tells the person to ask their admin.

Endpoint text that reaches a person or a log (a refusal body, a 429, an
error beside a 200) has the provider's key and header values masked, as
its chat turns do. With no pick, the person's own credentials (registry
accounts, then custom image models) come before anything a server key
pays for, Seedream on ARK_API_KEY included. Disconnecting a personal
provider or deleting a shared one deletes the image-model picks on it.

generate_image (MCP and resident) takes an optional `transparent`: only a
model marked so is sent `background: "transparent"`, and the result says
whether the cut-out was drawn. Analytics get `custom-personal` or
`custom-shared`, never the provider's name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ABWHJg7QHZpRjDADALswQZ
…e-model list

The custom provider form (Settings and Admin → Shared models) gets an
Image models section under the models, for the Chat Completions API type:
id, optional name, a Transparent switch, remove and Add image model. The
ids Fetch models found are offered for both lists. Admin's shared
provider row counts its image models.

Settings → Doop Agent → Image model lists each custom provider's image
models after the registry, one row per provider ("Name (shared)" for an
admin's), with a dropdown when it lists several. Strings in en and pt-BR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ABWHJg7QHZpRjDADALswQZ
@gganebnyi
gganebnyi force-pushed the feature/custom-provider-image-models branch from d39e23e to b882ff7 Compare November 25, 2026 09:00
@gganebnyi

Copy link
Copy Markdown
Author

@kgoedecke issues addressed

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants